#!/bin/env python2.6
# the prediction algorithm
def predict(next):
    if next in ['mit']:
        return 'an'
    if (next[0] not in 'aeio' or next == 'one' or next[:3] == 'eur') and \
       next[:2] not in ['un', 'ur', 'up', 'ul'] and \
       next[:4] not in ['hour'] and \
       next[:5] not in ['honor', 'hones'] and \
       True in [x in next for x in 'aeiou']:
        return 'a'
    if next in [x for x in 'bcdgjkpqtuvwyz'] or \
       next[:4] in ['unio', 'unic'] or \
       next[:5] in ['unite']:
        return 'a'
    if True not in [x in next for x in 'aeiou'] and \
       next[0] in [x for x in 'bcdgjkpqtuvwyz']:
        return 'a'
    return 'an'

# word generator
def fwords():
    from sys import stdin as si
    while 1:
        data = si.read(10240)
        if data == '':
            break
        while data[-1] != ' ':
            pad = si.read(1)
            if pad == '':
                break
            data += pad
        data = data.split()
        if data[-1] == '':
            data = data[:-1]
        for word in data:
            yield word
    return

words = fwords()

word = words.next()
next = words.next()

from sys import stdout as so
# calculate exceptions
exc = ''
while 1:
    try:
        if word in ['a', 'an']:
            if word == predict(next):
                exc += '0'
            else:
                exc += '1'
            so.write('a ')
        else:
            so.write(word + ' ')
        word = next
        next = words.next()
    except StopIteration:
        so.write(next)
        break

# compress exceptions
from bz2 import compress as c
exc = repr(c(exc)[10:])

# write exceptions
excf = open('partad.py', 'w')
excf.write('exc = ' + exc)
excf.close()
